/* Copyright (c) 2012 Mobile Developer Solutions. All rights reserved.
 * This software is available under the MIT License:
 * The MIT License
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
 * and associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software 
 * is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies 
 * or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 
 * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

/* api-geolocation
var getLocation = function() {
    
   
	
	
	var suc = function(p) {
        outLatitude.value = p.coords.latitude;
		outLongitude.value= p.coords.longitude;
		
		var mapwidth = parseInt($('#map').css("width"), 40);  // remove 'px' from width value
        var mapheight = parseInt($('#map').css("height"), 30);
		 $('#map').css('visibility','visible');
        $('#map').attr('src', "http://maps.googleapis.com/maps/api/staticmap?center=" + 
            p.coords.latitude + "," + p.coords.longitude + 
            "&zoom=13&size=" + mapwidth + "x" + mapheight + "&maptype=roadmap&markers=color:green%7C" +
            p.coords.latitude + "," + p.coords.longitude + "&sensor=false");
    };

    var locFail = function(error) {
                    alert('code: '    + error.code    + '\n' +
              'message: ' + error.message + '\n');
    };
	
	  var errorCallback_highAccuracy = function() {
        navigator.geolocation.getCurrentPosition(suc, locFail, {
			maximumAge : 60000,
            timeout : 3000,
            enableHighAccuracy : false
        });
    };
	
	 $('#map').css('visibility','hidden');
    $("#cur_position").html("Getting geolocation . . .");
    console.log("Getting geolocation . . .");
	 navigator.geolocation.getCurrentPosition(suc, errorCallback_highAccuracy ,{
		  		maximumAge : 60000,
            	timeout : 3000,
                enableHighAccuracy : true
            });
}; 
*/
var getLocation = function() {
	
var map = document.getElementById('map');

var success = function(pos) { 

outLatitude.value = pos.coords.latitude;
outLongitude.value= pos.coords.longitude;

map.style.display='block';
map.style.visibility='visible';
var mapwidth = 360; // a mungy compromise between the 2 sizes
var mapheight = 280; // since we can't get w / h dynamically
map.src ="http://maps.googleapis.com/maps/api/staticmap?center=" + pos.coords.latitude+","+ pos.coords.longitude+"&zoom=14&size=" + mapwidth +"x"+mapheight+"&maptype=roadmap&markers=color:green%7C"+pos.coords.latitude+","+ pos.coords.longitude+"&sensor=false";
};


var fail = function(error) {
alert("Cannot be located now attempting to gain location again.");
var success2 = function(pos) { 

outLatitude.value = pos.coords.latitude;
outLongitude.value= pos.coords.longitude;

map.style.display='block';
map.style.visibility='visible';
var mapwidth = 360; // a mungy compromise between the 2 sizes
var mapheight = 280; // since we can't get w / h dynamically
map.src ="http://maps.googleapis.com/maps/api/staticmap?center=" + pos.coords.latitude+","+ pos.coords.longitude+"&zoom=14&size=" + mapwidth +"x"+mapheight+"&maptype=roadmap&markers=color:green%7C"+pos.coords.latitude+","+ pos.coords.longitude+"&sensor=false";
};


var fail2 = function(error) {
	alert("Cannot be located now");
outLatitude.value = 0;
outLongitude.value= 0;
};

map.style.display ='none';
console.log("Getting geolocation . . .");


navigator.geolocation.getCurrentPosition(success, fail,{
		  		maximumAge :0,
            	timeout : 5000,
                enableHighAccuracy : true
            });
};

map.style.display ='none';
console.log("Getting geolocation . . .");


navigator.geolocation.getCurrentPosition(success, fail,{
		  		maximumAge :0,
            	timeout : 5000,
                enableHighAccuracy : true
            });
};
